package com.briup.smartlab.web.controller;

import com.briup.smartlab.bean.EnvDetail;
import com.briup.smartlab.service.IEnvDetailService;
import com.briup.smartlab.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2023-07-19
 */
@Api(tags = "环境数据管理模块")
@RestController
@RequestMapping("/envDetail")
public class EnvDetailController {
    @Autowired //表示对象从ioc容器中获取
    private IEnvDetailService service;


    @ApiOperation("根据编号查询环境信息")
    @GetMapping("/{id}")
    public Response findById(@PathVariable String id){
        //1.接收参数
        //2.调用service方法
        EnvDetail envDetail = service.findById(id);
        //3.将数据返回响应体中
        return Response.success(envDetail);
    }
    @ApiOperation("新增或修改环境数据")
    @PostMapping("/saveOrUpdate")
    public Response saveOrUpdate(@RequestBody EnvDetail detail){
        //1.接收请求体中json格式字符串参数
        //2.调用service方法
        service.saveOrUpdate(detail);
        //3.返回数据
        return Response.success();
    }
    @ApiOperation("根据id删除指定环境数据")
    @DeleteMapping("/{id}")
    public Response deletById(@PathVariable String id){
        service.deleteById(id);
        return Response.success();
    }
    @ApiOperation("批量删除环境数据")
    @DeleteMapping("/batch")
    public Response deletByBatch(@RequestBody List<String> ids){
        service.deleteByBatch(ids);
        return Response.success();
    }
}
